<?php

namespace App\Services\GiftVipPurchase;

use App\Models\User;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class GiftVipPurchase
{
	/**
	 * @var User
	 */
	protected $self;

	/**
	 * @var User
	 */
	protected $guser;

	protected $cards = 0;

	public function __construct(User $self, User $guser, $cards)
	{
		$this->self = $self;
		$this->guser = $guser;
		$this->cards = $cards;
	}

	protected function transfer()
	{
		DB::transaction(function () {
			$data = ['gift_user_id' => $this->guser->id];
			account_cards($this->self)->minusGiftVipCards($this->cards, $data);

			$data = ['parent_user_id' => $this->self->id];
			account_cards($this->guser)->plusgetVipCards($this->cards, $data);
		});
	}

	public function apply()
	{

		$this->transfer();
	}
}
